/**
 * @(#)TimeModelParentTempleteService.java 2017年2月9日
 * Copyright(C) 2017 ZHEXIN IT CO.,LTD. All rights reserved.
 */
package org.jsbd.boss.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.jsbd.boss.dao.ITimeModelParentTempleteDAO;
import org.jsbd.boss.dao.ITimeModelTempleteDAO;
import org.jsbd.boss.domian.channel.TimeBaseModel;
import org.jsbd.boss.domian.channel.TimeModelParentTemplete;
import org.jsbd.boss.domian.channel.TimeModelTemplete;
import org.jsbd.boss.service.ITimeModelParentTempleteService;
import org.jsbd.boss.service.ITimeModelTempleteService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

/**
 * TODO 请加入本类的说明
 * 
 * @author <a href="mailto:xupengcheng@zhexinit.com" >徐鹏程</a>
 * @version 1.0.0
 */
@Service
public class TimeModelParentTempleteService implements ITimeModelParentTempleteService {
	public static final Logger LOGGER = LoggerFactory.getLogger(TimeModelParentTempleteService.class);

	@Resource
	private ITimeModelParentTempleteDAO timeModelParentTempleteDAO;

	@Resource
	private ITimeModelTempleteDAO timeModelTempleteDAO;
	
	@Resource
	private ITimeModelTempleteService timeModelTempleteService;
	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.jsbd.boss.service.ITimeModelParentTempleteService#insertTemplete(
	 * org.jsbd.boss.domian.channel.TimeModelParentTemplete)
	 */
	@Override
	public Integer insertTemplete(TimeModelParentTemplete templete) {
		return timeModelParentTempleteDAO.insertTemplete(templete);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.jsbd.boss.service.ITimeModelParentTempleteService#
	 * selectTempletePageListMap
	 * (org.jsbd.boss.domian.channel.TimeModelParentTemplete)
	 */
	@Override
	public Map<String, Object> selectTempletePageListMap(TimeModelParentTemplete form) {
		return timeModelParentTempleteDAO.selectTempletePageListMap(form);
	}
	
	@Override
	public List<TimeModelParentTemplete> selectTempleteList(TimeModelParentTemplete form) {
		return timeModelParentTempleteDAO.selectAllTemplete(form);
	}

	@Override
	public TimeModelParentTemplete selectTemplete(TimeModelParentTemplete form) {
		TimeModelParentTemplete templete = timeModelParentTempleteDAO.selectTemplete(form);
		if(templete != null){
			Integer id = templete.getId();
			TimeModelTemplete queryTemp = new TimeModelTemplete();
			queryTemp.setParentId(id);
			List<TimeModelTemplete> templeteList = timeModelTempleteDAO.selectTemplete(queryTemp);
			if(templeteList == null || templeteList.size() == 0){
				List<TimeBaseModel> allBaseModelList = timeModelTempleteService.selectAllBaseModel();
				for(TimeBaseModel baseModel : allBaseModelList){
					TimeModelTemplete baseTemplteModel = new TimeModelTemplete();
					baseTemplteModel.setParentId(id);
					baseTemplteModel.setCurrRate(baseModel.getCurrRate());
					baseTemplteModel.setRateTime(baseModel.getRateTime());
					baseTemplteModel.setTotalRate(baseModel.getTotalRate());
					timeModelTempleteDAO.insertTemplete(baseTemplteModel);
				}
			}
		}
		return templete;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.jsbd.boss.service.ITimeModelParentTempleteService#updateTemplete(
	 * org.jsbd.boss.domian.channel.TimeModelParentTemplete)
	 */
	@Override
	public Integer updateTemplete(TimeModelParentTemplete templete) {
		return timeModelParentTempleteDAO.updateTemplete(templete);
	}

	/* (non-Javadoc)
	 * @see org.jsbd.boss.service.ITimeModelParentTempleteService#deleteTemplete(java.lang.String)
	 */
	@Override
	public void deleteTemplete(Integer id) {
		timeModelParentTempleteDAO.deleteTemplete(id);
	}
}
